// @ts-nocheck
import './public-path';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

declare global {
  interface Window {
    __POWERED_BY_QIANKUN__: any;
    __INJECTED_PUBLIC_PATH_BY_QIANKUN__: any;
  }
}

let app: any;

function render() {
  platformBrowserDynamic()
    .bootstrapModule(AppModule)
    .then(ref => {
      app = ref;
    })
    .catch(err => console.error(err));
}

if ((window as any).__POWERED_BY_QIANKUN__) {
  // eslint-disable-next-line no-undef
  __webpack_public_path__ = (window as any).__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
} else {
  render();
}

export async function bootstrap() {
  console.log('[angular-app] angular app bootstraped');
}

export async function mount(props: any) {
  console.log('[angular-app] props from main framework', props);
  render();
}

export async function unmount() {
  console.log('[angular-app] angular app unmount');
  if (app) {
    app.destroy();
    app = null;
  }
}